import java.util.Scanner;
import java.util.*;
/*
 **@Author:刘淑钰
 **Created on 2021/12/8
 */
public class Main {
    public void solution(int re[][],int n){
        int i,j,k;
        for(i=1;i<n+1;i++){
            for(j=1;j<=i;j++)
                if((i%j==0)&&((i/j)*re[0][j]>re[1][i]))
                    re[1][i]=(i/j)*re[0][j];
            for(j=1,k=i-1;j<=k;j++,k--)
                if(re[1][j]+re[1][k]>re[1][i])
                    re[1][i]=re[1][j]+re[1][k];
        }
        return;
    }

    public static void main(String[] args) {
        int n;
        Scanner in = new Scanner(System.in);
        Main test = new Main();
        n = in.nextInt();

        int res[][] = new int[2][n + 2];
        int i,m;
        for(i=1;i<n+1;i++)
        {
            m=in.nextInt();
            res[0][i]=m;
            res[1][i]=0;
        }
        test.solution(res,n);
        System.out.print(res[1][n]);
    }
}

